﻿using System.Text.Json.Serialization;
using Simple.Common.Extensions;
using Simple.Common.Helpers;

namespace Simple.Services;

public class LeaveMessageModel : ModelBase
{
    /// <summary>
    /// 主键
    /// </summary>
    public Guid? Id { get; set; }

    /// <summary>
    /// 留言内容
    /// </summary>
    public string? LeaveMessageContent { get; set; }

    /// <summary>
    /// 留言时间
    /// </summary>
    public DateTime? LeaveMessageTime { get; set; }

    /// <summary>
    /// 留言人id
    /// </summary>
    public string? LeaveMessageUserId { get; set; }

    /// <summary>
    /// 留言人姓名
    /// </summary>
    public string? LeaveMessageUserName { get; set; }

    /// <summary>
    /// 班级动态
    /// </summary>
    public ClassDynamic ClassDynamic = new ClassDynamic();

    /// <summary>
    /// 班级动态Id
    /// </summary>
    public Guid? ClassDynamicId { get; set; } = null;

    /// <summary>
    /// 所在班级id
    /// </summary>
    public Guid? ClassId { get; set; }

    /// <summary>
    /// 班级名称
    /// </summary>
    public string? ClassName { get; set; }

    /// <summary>
    /// 留言回复
    /// </summary>
    public List<LeaveMessageReply> Replys = new List<LeaveMessageReply>();

    /// <summary>
    /// 是否回复
    /// </summary>
    public bool IsReply { get; set; } = false;

    /// <summary>
    /// 是否发布
    /// </summary>
    public bool IsPublish { get; set; } = true;

    /// <summary>
    /// 家长或老师标识
    /// </summary>
    public int? LoginType { get; set; }

    /// <summary>
    /// 关联幼儿Id
    /// </summary>
    public Guid? RelationshipChildrenId { get; set; }

    /// <summary>
    /// 幼儿姓名
    /// </summary>
    public string? RelationshipChildrenName { get; set; }

    /// <summary>
    /// 关系名称
    /// </summary>
    public string? RelationshipValue { get; set; }

    /// <summary>
    /// 留言人图片Id
    /// </summary>
    public string? LeaveMessageUserImageId { get; set; }

    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<ClassDynamicLeaveMessage, LeaveMessageModel>()
            .ForMember(d => d.IsReply, options => options.MapFrom(s => s.Replys.Any()))
            .ForMember(p => p.RelationshipValue, options => options.MapFrom(p => p.Relationship.HasValue ? ((EnumParentRelationship)Enum.Parse(typeof(EnumParentRelationship), (p.Relationship ?? 0).ToString())).GetEnumDescription() : (p.LoginType == 1 || !p.LoginType.HasValue ? "老师" : string.Empty)));

        profile.CreateMap<LeaveMessageModel, ClassDynamicLeaveMessage>()
            .ForMember(d => d.IsReply, options => options.MapFrom(s => s.Replys.Any()));

    }

}
